"""
 -*- coding: utf-8-*-
 @File: page_pet_mgt.py
 @Author: chen
 @time: 2024/01/10/ 20:28
"""
from ui_test.page_po_test.page_business.page_base import BasePage


class PetMgtPage(BasePage):
    def goto_add_pet_page(self):
        btn_add_pet = (self.by.XPATH, '//*[text()="Add New Pet"]')
        self.logger.info("点击添加宠物按钮")
        self.do_click(btn_add_pet)
        from ui_test.page_po_test.page_business.page_add_pet import AddPetPage
        self.logger.info("进入新增宠物页面")
        return AddPetPage(self.driver)

    def add_new_pet(self, pet_name, pet_birth, pet_type):
        self.goto_add_pet_page(). \
            add_to_pet_mgt_page(pet_name, pet_birth, pet_type)
        return self

    def delete_pet(self, pet_name):
        btn_delete = (self.by.XPATH, f'//*[text()="{pet_name}"]/..//*[text()="Delete Pet"]')
        self.logger.info(f"删除宠物：{pet_name}")
        self.do_click(btn_delete)
        return self

    def pet_is_exist(self, pet_name):
        """判断宠物是否存在"""
        text_pet = (self.by.XPATH, f'//*[text()="{pet_name}"]')
        pet_ele = self.do_find(text_pet).text
        if pet_ele:
            self.logger.info(f"宠物：{pet_name}--->已存在")
            return True
        else:
            self.logger.info(f"宠物：{pet_name}--->不存在")
            return False
